
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>5-3 编写 Loader · 深入浅出 Webpack</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="吴浩麟">
        <meta name="identifier" content="9787121331725" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-modal/index.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="5-4编写Plugin.html" />
    
    
    <link rel="prev" href="5-2输出文件分析.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]};
    </script>


    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
  
  

  

  
  
  

<li class="chapter " data-level="1.1" data-path="../">
  
  <a href="../">
    
                    
                    深入浅出 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.2" data-path="../前言.html">
  
  <a href="../前言.html">
    
                    
                    前言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3" data-path="../1入门/">
  
  <a href="../1入门/">
    
                    
                    第1章 入门
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.3.1" data-path="../1入门/1-1前端的发展.html">
  
  <a href="../1入门/1-1前端的发展.html">
    
                    
                    1-1 前端的发展
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.2" data-path="../1入门/1-2常见的构建工具及对比.html">
  
  <a href="../1入门/1-2常见的构建工具及对比.html">
    
                    
                    1-2 常见的构建工具及对比
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.3" data-path="../1入门/1-3安装与使用.html">
  
  <a href="../1入门/1-3安装与使用.html">
    
                    
                    1-3 安装与使用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.4" data-path="../1入门/1-4使用Loader.html">
  
  <a href="../1入门/1-4使用Loader.html">
    
                    
                    1-4 使用 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.5" data-path="../1入门/1-5使用Plugin.html">
  
  <a href="../1入门/1-5使用Plugin.html">
    
                    
                    1-5 使用 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.6" data-path="../1入门/1-6使用DevServer.html">
  
  <a href="../1入门/1-6使用DevServer.html">
    
                    
                    1-6 使用 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.7" data-path="../1入门/1-7核心概念.html">
  
  <a href="../1入门/1-7核心概念.html">
    
                    
                    1-7 核心概念
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.4" data-path="../2配置/">
  
  <a href="../2配置/">
    
                    
                    第2章 配置
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.4.1" data-path="../2配置/2-1Entry.html">
  
  <a href="../2配置/2-1Entry.html">
    
                    
                    2-1 Entry
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.2" data-path="../2配置/2-2Output.html">
  
  <a href="../2配置/2-2Output.html">
    
                    
                    2-2 Output
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.3" data-path="../2配置/2-3Module.html">
  
  <a href="../2配置/2-3Module.html">
    
                    
                    2-3 Module
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.4" data-path="../2配置/2-4Resolve.html">
  
  <a href="../2配置/2-4Resolve.html">
    
                    
                    2-4 Resolve
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.5" data-path="../2配置/2-5Plugins.html">
  
  <a href="../2配置/2-5Plugins.html">
    
                    
                    2-5 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.6" data-path="../2配置/2-6DevServer.html">
  
  <a href="../2配置/2-6DevServer.html">
    
                    
                    2-6 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.7" data-path="../2配置/2-7其它配置项.html">
  
  <a href="../2配置/2-7其它配置项.html">
    
                    
                    2-7 其它配置项
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.8" data-path="../2配置/2-8整体配置结构.html">
  
  <a href="../2配置/2-8整体配置结构.html">
    
                    
                    2-8 整体配置结构
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.9" data-path="../2配置/2-9多种配置类型.html">
  
  <a href="../2配置/2-9多种配置类型.html">
    
                    
                    2-9 多种配置类型
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.10" data-path="../2配置/2-10配置总结.html">
  
  <a href="../2配置/2-10配置总结.html">
    
                    
                    2-10 配置总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.5" data-path="../3实战/">
  
  <a href="../3实战/">
    
                    
                    第3章 实战
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.5.1" data-path="../3实战/3-1使用ES6语言.html">
  
  <a href="../3实战/3-1使用ES6语言.html">
    
                    
                    3-1 使用 ES6 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.2" data-path="../3实战/3-2使用TypeScript语言.html">
  
  <a href="../3实战/3-2使用TypeScript语言.html">
    
                    
                    3-2 使用 TypeScript 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.3" data-path="../3实战/3-3使用Flow检查器.html">
  
  <a href="../3实战/3-3使用Flow检查器.html">
    
                    
                    3-3 使用 Flow 检查器
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.4" data-path="../3实战/3-4使用SCSS语言.html">
  
  <a href="../3实战/3-4使用SCSS语言.html">
    
                    
                    3-4 使用 SCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.5" data-path="../3实战/3-5使用PostCSS.html">
  
  <a href="../3实战/3-5使用PostCSS.html">
    
                    
                    3-5 使用 PostCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.6" data-path="../3实战/3-6使用React框架.html">
  
  <a href="../3实战/3-6使用React框架.html">
    
                    
                    3-6 使用 React 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.7" data-path="../3实战/3-7使用Vue框架.html">
  
  <a href="../3实战/3-7使用Vue框架.html">
    
                    
                    3-7 使用 Vue 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.8" data-path="../3实战/3-8使用Angular2框架.html">
  
  <a href="../3实战/3-8使用Angular2框架.html">
    
                    
                    3-8 使用 Angular2 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.9" data-path="../3实战/3-9为单页应用生成HTML.html">
  
  <a href="../3实战/3-9为单页应用生成HTML.html">
    
                    
                    3-9 为单页应用生成 HTML
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.10" data-path="../3实战/3-10管理多个单页应用.html">
  
  <a href="../3实战/3-10管理多个单页应用.html">
    
                    
                    3-10 管理多个单页应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.11" data-path="../3实战/3-11构建同构应用.html">
  
  <a href="../3实战/3-11构建同构应用.html">
    
                    
                    3-11 构建同构应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.12" data-path="../3实战/3-12构建Electron应用.html">
  
  <a href="../3实战/3-12构建Electron应用.html">
    
                    
                    3-12 构建 Electron 应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.13" data-path="../3实战/3-13构建Npm模块.html">
  
  <a href="../3实战/3-13构建Npm模块.html">
    
                    
                    3-13 构建 Npm 模块
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.14" data-path="../3实战/3-14构建离线应用.html">
  
  <a href="../3实战/3-14构建离线应用.html">
    
                    
                    3-14 构建离线应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.15" data-path="../3实战/3-15搭配NpmScript.html">
  
  <a href="../3实战/3-15搭配NpmScript.html">
    
                    
                    3-15 搭配 Npm Script
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.16" data-path="../3实战/3-16检查代码.html">
  
  <a href="../3实战/3-16检查代码.html">
    
                    
                    3-16 检查代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.17" data-path="../3实战/3-17通过Node.jsAPI启动Webpack.html">
  
  <a href="../3实战/3-17通过Node.jsAPI启动Webpack.html">
    
                    
                    3-17 通过 Node.js API 启动 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.18" data-path="../3实战/3-18使用WebpackDevMiddleware.html">
  
  <a href="../3实战/3-18使用WebpackDevMiddleware.html">
    
                    
                    3-18 使用 Webpack Dev Middleware
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.19" data-path="../3实战/3-19加载图片.html">
  
  <a href="../3实战/3-19加载图片.html">
    
                    
                    3-19 加载图片
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.20" data-path="../3实战/3-20加载SVG.html">
  
  <a href="../3实战/3-20加载SVG.html">
    
                    
                    3-20 加载SVG
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.21" data-path="../3实战/3-21加载SourceMap.html">
  
  <a href="../3实战/3-21加载SourceMap.html">
    
                    
                    3-21 加载 Source Map
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.22" data-path="../3实战/3-22实战总结.html">
  
  <a href="../3实战/3-22实战总结.html">
    
                    
                    3-22 实战总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.6" data-path="../4优化/">
  
  <a href="../4优化/">
    
                    
                    第4章 优化
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.6.1" data-path="../4优化/4-1缩小文件搜索范围.html">
  
  <a href="../4优化/4-1缩小文件搜索范围.html">
    
                    
                    4-1 缩小文件搜索范围
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.2" data-path="../4优化/4-2使用DllPlugin.html">
  
  <a href="../4优化/4-2使用DllPlugin.html">
    
                    
                    4-2 使用 DllPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.3" data-path="../4优化/4-3使用HappyPack.html">
  
  <a href="../4优化/4-3使用HappyPack.html">
    
                    
                    4-3 使用 HappyPack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.4" data-path="../4优化/4-4使用ParallelUglifyPlugin.html">
  
  <a href="../4优化/4-4使用ParallelUglifyPlugin.html">
    
                    
                    4-4 使用 ParallelUglifyPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.5" data-path="../4优化/4-5使用自动刷新.html">
  
  <a href="../4优化/4-5使用自动刷新.html">
    
                    
                    4-5 使用自动刷新
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.6" data-path="../4优化/4-6开启模块热替换.html">
  
  <a href="../4优化/4-6开启模块热替换.html">
    
                    
                    4-6 开启模块热替换
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.7" data-path="../4优化/4-7区分环境.html">
  
  <a href="../4优化/4-7区分环境.html">
    
                    
                    4-7 区分环境
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.8" data-path="../4优化/4-8压缩代码.html">
  
  <a href="../4优化/4-8压缩代码.html">
    
                    
                    4-8 压缩代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.9" data-path="../4优化/4-9CDN加速.html">
  
  <a href="../4优化/4-9CDN加速.html">
    
                    
                    4-9 CDN 加速
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.10" data-path="../4优化/4-10使用TreeShaking.html">
  
  <a href="../4优化/4-10使用TreeShaking.html">
    
                    
                    4-10 使用 Tree Shaking
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.11" data-path="../4优化/4-11提取公共代码.html">
  
  <a href="../4优化/4-11提取公共代码.html">
    
                    
                    4-11 提取公共代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.12" data-path="../4优化/4-12按需加载.html">
  
  <a href="../4优化/4-12按需加载.html">
    
                    
                    4-12 按需加载
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.13" data-path="../4优化/4-13使用Prepack.html">
  
  <a href="../4优化/4-13使用Prepack.html">
    
                    
                    4-13 使用 Prepack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.14" data-path="../4优化/4-14开启ScopeHoisting.html">
  
  <a href="../4优化/4-14开启ScopeHoisting.html">
    
                    
                    4-14 开启 Scope Hoisting
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.15" data-path="../4优化/4-15输出分析.html">
  
  <a href="../4优化/4-15输出分析.html">
    
                    
                    4-15 输出分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.16" data-path="../4优化/4-16优化总结.html">
  
  <a href="../4优化/4-16优化总结.html">
    
                    
                    4-16 优化总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.7" data-path="./">
  
  <a href="./">
    
                    
                    第5章 原理
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.7.1" data-path="5-1工作原理概括.html">
  
  <a href="5-1工作原理概括.html">
    
                    
                    5-1 工作原理概括
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.2" data-path="5-2输出文件分析.html">
  
  <a href="5-2输出文件分析.html">
    
                    
                    5-2 输出文件分析
            
    </a>
    

    
</li>

<li class="chapter active" data-level="1.7.3" data-path="5-3编写Loader.html">
  
  <a href="5-3编写Loader.html">
    
                    
                    5-3 编写 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.4" data-path="5-4编写Plugin.html">
  
  <a href="5-4编写Plugin.html">
    
                    
                    5-4 编写 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.5" data-path="5-5调试Webpack.html">
  
  <a href="5-5调试Webpack.html">
    
                    
                    5-5 调试 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.6" data-path="5-6原理总结.html">
  
  <a href="5-6原理总结.html">
    
                    
                    5-6 原理总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.8" >
  
      <span>
            
                    
                    附录
            
    </span>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.8.1" data-path="../附录/常用Loaders.html">
  
  <a href="../附录/常用Loaders.html">
    
                    
                    常用 Loaders
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.2" data-path="../附录/常用Plugins.html">
  
  <a href="../附录/常用Plugins.html">
    
                    
                    常用 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.3" data-path="../附录/其它Webpack学习资源.html">
  
  <a href="../附录/其它Webpack学习资源.html">
    
                    
                    其它 Webpack 学习资源
            
    </a>
    

    
</li>


    </ul>
    
</li>


  

  <li class="divider"></li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >5-3 编写 Loader</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="5-3-&#x7F16;&#x5199;-loader">5-3 &#x7F16;&#x5199; Loader</h1>
<p>Loader &#x5C31;&#x50CF;&#x662F;&#x4E00;&#x4E2A;&#x7FFB;&#x8BD1;&#x5458;&#xFF0C;&#x80FD;&#x628A;&#x6E90;&#x6587;&#x4EF6;&#x7ECF;&#x8FC7;&#x8F6C;&#x5316;&#x540E;&#x8F93;&#x51FA;&#x65B0;&#x7684;&#x7ED3;&#x679C;&#xFF0C;&#x5E76;&#x4E14;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x8FD8;&#x53EF;&#x4EE5;&#x94FE;&#x5F0F;&#x7684;&#x7ECF;&#x8FC7;&#x591A;&#x4E2A;&#x7FFB;&#x8BD1;&#x5458;&#x7FFB;&#x8BD1;&#x3002;</p>
<p>&#x4EE5;&#x5904;&#x7406; SCSS &#x6587;&#x4EF6;&#x4E3A;&#x4F8B;&#xFF1A;</p>
<ol>
<li>SCSS &#x6E90;&#x4EE3;&#x7801;&#x4F1A;&#x5148;&#x4EA4;&#x7ED9; sass-loader &#x628A; SCSS &#x8F6C;&#x6362;&#x6210; CSS&#xFF1B;</li>
<li>&#x628A; sass-loader &#x8F93;&#x51FA;&#x7684; CSS &#x4EA4;&#x7ED9; css-loader &#x5904;&#x7406;&#xFF0C;&#x627E;&#x51FA; CSS &#x4E2D;&#x4F9D;&#x8D56;&#x7684;&#x8D44;&#x6E90;&#x3001;&#x538B;&#x7F29; CSS &#x7B49;&#xFF1B;</li>
<li>&#x628A; css-loader &#x8F93;&#x51FA;&#x7684; CSS &#x4EA4;&#x7ED9; style-loader &#x5904;&#x7406;&#xFF0C;&#x8F6C;&#x6362;&#x6210;&#x901A;&#x8FC7;&#x811A;&#x672C;&#x52A0;&#x8F7D;&#x7684;  JavaScript &#x4EE3;&#x7801;&#xFF1B;</li>
</ol>
<p>&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x4EE5;&#x4E0A;&#x7684;&#x5904;&#x7406;&#x8FC7;&#x7A0B;&#x9700;&#x8981;&#x6709;&#x987A;&#x5E8F;&#x7684;&#x94FE;&#x5F0F;&#x6267;&#x884C;&#xFF0C;&#x5148; sass-loader &#x518D; css-loader &#x518D; style-loader&#x3002;
&#x4EE5;&#x4E0A;&#x5904;&#x7406;&#x7684; Webpack &#x76F8;&#x5173;&#x914D;&#x7F6E;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-built_in">module</span>: {
    rules: [
      {
        <span class="hljs-comment">// &#x589E;&#x52A0;&#x5BF9; SCSS &#x6587;&#x4EF6;&#x7684;&#x652F;&#x6301;</span>
        test: <span class="hljs-regexp">/\.scss$/</span>,
        <span class="hljs-comment">// SCSS &#x6587;&#x4EF6;&#x7684;&#x5904;&#x7406;&#x987A;&#x5E8F;&#x4E3A;&#x5148; sass-loader &#x518D; css-loader &#x518D; style-loader</span>
        use: [
          <span class="hljs-string">&apos;style-loader&apos;</span>,
          {
            loader:<span class="hljs-string">&apos;css-loader&apos;</span>,
            <span class="hljs-comment">// &#x7ED9; css-loader &#x4F20;&#x5165;&#x914D;&#x7F6E;&#x9879;</span>
            options:{
              minimize:<span class="hljs-literal">true</span>, 
            }
          },
          <span class="hljs-string">&apos;sass-loader&apos;</span>],
      },
    ]
  },
};
</code></pre>
<h2 id="loader-&#x7684;&#x804C;&#x8D23;">Loader &#x7684;&#x804C;&#x8D23;</h2>
<p>&#x7531;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#xFF1A;&#x4E00;&#x4E2A; Loader &#x7684;&#x804C;&#x8D23;&#x662F;&#x5355;&#x4E00;&#x7684;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5B8C;&#x6210;&#x4E00;&#x79CD;&#x8F6C;&#x6362;&#x3002;
&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x6E90;&#x6587;&#x4EF6;&#x9700;&#x8981;&#x7ECF;&#x5386;&#x591A;&#x6B65;&#x8F6C;&#x6362;&#x624D;&#x80FD;&#x6B63;&#x5E38;&#x4F7F;&#x7528;&#xFF0C;&#x5C31;&#x901A;&#x8FC7;&#x591A;&#x4E2A; Loader &#x53BB;&#x8F6C;&#x6362;&#x3002;
&#x5728;&#x8C03;&#x7528;&#x591A;&#x4E2A; Loader &#x53BB;&#x8F6C;&#x6362;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x65F6;&#xFF0C;&#x6BCF;&#x4E2A; Loader &#x4F1A;&#x94FE;&#x5F0F;&#x7684;&#x987A;&#x5E8F;&#x6267;&#x884C;&#xFF0C;
&#x7B2C;&#x4E00;&#x4E2A; Loader &#x5C06;&#x4F1A;&#x62FF;&#x5230;&#x9700;&#x5904;&#x7406;&#x7684;&#x539F;&#x5185;&#x5BB9;&#xFF0C;&#x4E0A;&#x4E00;&#x4E2A; Loader &#x5904;&#x7406;&#x540E;&#x7684;&#x7ED3;&#x679C;&#x4F1A;&#x4F20;&#x7ED9;&#x4E0B;&#x4E00;&#x4E2A;&#x63A5;&#x7740;&#x5904;&#x7406;&#xFF0C;&#x6700;&#x540E;&#x7684; Loader &#x5C06;&#x5904;&#x7406;&#x540E;&#x7684;&#x6700;&#x7EC8;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x7ED9; Webpack&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x5728;&#x4F60;&#x5F00;&#x53D1;&#x4E00;&#x4E2A; Loader &#x65F6;&#xFF0C;&#x8BF7;&#x4FDD;&#x6301;&#x5176;&#x804C;&#x8D23;&#x7684;&#x5355;&#x4E00;&#x6027;&#xFF0C;&#x4F60;&#x53EA;&#x9700;&#x5173;&#x5FC3;&#x8F93;&#x5165;&#x548C;&#x8F93;&#x51FA;&#x3002;</p>
<h2 id="loader-&#x57FA;&#x7840;">Loader &#x57FA;&#x7840;</h2>
<p>&#x7531;&#x4E8E; Webpack &#x662F;&#x8FD0;&#x884C;&#x5728; Node.js &#x4E4B;&#x4E0A;&#x7684;&#xFF0C;&#x4E00;&#x4E2A; Loader &#x5176;&#x5B9E;&#x5C31;&#x662F;&#x4E00;&#x4E2A; Node.js &#x6A21;&#x5757;&#xFF0C;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x9700;&#x8981;&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x3002;
&#x8FD9;&#x4E2A;&#x5BFC;&#x51FA;&#x7684;&#x51FD;&#x6570;&#x7684;&#x5DE5;&#x4F5C;&#x5C31;&#x662F;&#x83B7;&#x5F97;&#x5904;&#x7406;&#x524D;&#x7684;&#x539F;&#x5185;&#x5BB9;&#xFF0C;&#x5BF9;&#x539F;&#x5185;&#x5BB9;&#x6267;&#x884C;&#x5904;&#x7406;&#x540E;&#xFF0C;&#x8FD4;&#x56DE;&#x5904;&#x7406;&#x540E;&#x7684;&#x5185;&#x5BB9;&#x3002;</p>
<p>&#x4E00;&#x4E2A;&#x6700;&#x7B80;&#x5355;&#x7684; Loader &#x7684;&#x6E90;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source</span>) </span>{
  <span class="hljs-comment">// source &#x4E3A; compiler &#x4F20;&#x9012;&#x7ED9; Loader &#x7684;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x7684;&#x539F;&#x5185;&#x5BB9;</span>
  <span class="hljs-comment">// &#x8BE5;&#x51FD;&#x6570;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x5904;&#x7406;&#x540E;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x8FD9;&#x91CC;&#x7B80;&#x5355;&#x8D77;&#x89C1;&#xFF0C;&#x76F4;&#x63A5;&#x628A;&#x539F;&#x5185;&#x5BB9;&#x8FD4;&#x56DE;&#x4E86;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x8BE5; Loader &#x6CA1;&#x6709;&#x505A;&#x4EFB;&#x4F55;&#x8F6C;&#x6362;</span>
  <span class="hljs-keyword">return</span> source;
};
</code></pre>
<p>&#x7531;&#x4E8E; Loader &#x8FD0;&#x884C;&#x5728; Node.js &#x4E2D;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#x4EFB;&#x4F55; Node.js &#x81EA;&#x5E26;&#x7684; API&#xFF0C;&#x6216;&#x8005;&#x5B89;&#x88C5;&#x7B2C;&#x4E09;&#x65B9;&#x6A21;&#x5757;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> sass = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;node-sass&apos;</span>);
<span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source</span>) </span>{
  <span class="hljs-keyword">return</span> sass(source);
};
</code></pre>
<h2 id="loader-&#x8FDB;&#x9636;">Loader &#x8FDB;&#x9636;</h2>
<p>&#x4EE5;&#x4E0A;&#x53EA;&#x662F;&#x4E2A;&#x6700;&#x7B80;&#x5355;&#x7684; Loader&#xFF0C;Webpack &#x8FD8;&#x63D0;&#x4F9B;&#x4E00;&#x4E9B; API &#x4F9B; Loader &#x8C03;&#x7528;&#xFF0C;&#x4E0B;&#x9762;&#x6765;&#x4E00;&#x4E00;&#x4ECB;&#x7ECD;&#x3002;</p>
<h3 id="&#x83B7;&#x5F97;-loader-&#x7684;-options">&#x83B7;&#x5F97; Loader &#x7684; options</h3>
<p>&#x5728;&#x6700;&#x4E0A;&#x9762;&#x5904;&#x7406; SCSS &#x6587;&#x4EF6;&#x7684; Webpack &#x914D;&#x7F6E;&#x4E2D;&#xFF0C;&#x7ED9; css-loader &#x4F20;&#x4E86; options &#x53C2;&#x6570;&#xFF0C;&#x4EE5;&#x63A7;&#x5236; css-loader&#x3002;
&#x5982;&#x4F55;&#x5728;&#x81EA;&#x5DF1;&#x7F16;&#x5199;&#x7684; Loader &#x4E2D;&#x83B7;&#x53D6;&#x5230;&#x7528;&#x6237;&#x4F20;&#x5165;&#x7684; options &#x5462;&#xFF1F;&#x9700;&#x8981;&#x8FD9;&#x6837;&#x505A;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> loaderUtils = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;loader-utils&apos;</span>);
<span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source</span>) </span>{
  <span class="hljs-comment">// &#x83B7;&#x53D6;&#x5230;&#x7528;&#x6237;&#x7ED9;&#x5F53;&#x524D; Loader &#x4F20;&#x5165;&#x7684; options</span>
  <span class="hljs-keyword">const</span> options = loaderUtils.getOptions(<span class="hljs-keyword">this</span>);
  <span class="hljs-keyword">return</span> source;
};
</code></pre>
<h3 id="&#x8FD4;&#x56DE;&#x5176;&#x5B83;&#x7ED3;&#x679C;">&#x8FD4;&#x56DE;&#x5176;&#x5B83;&#x7ED3;&#x679C;</h3>
<p>&#x4E0A;&#x9762;&#x7684; Loader &#x90FD;&#x53EA;&#x662F;&#x8FD4;&#x56DE;&#x4E86;&#x539F;&#x5185;&#x5BB9;&#x8F6C;&#x6362;&#x540E;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x4F46;&#x6709;&#x4E9B;&#x573A;&#x666F;&#x4E0B;&#x8FD8;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x9664;&#x4E86;&#x5185;&#x5BB9;&#x4E4B;&#x5916;&#x7684;&#x4E1C;&#x897F;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#x4EE5;&#x7528; babel-loader &#x8F6C;&#x6362; ES6 &#x4EE3;&#x7801;&#x4E3A;&#x4F8B;&#xFF0C;&#x5B83;&#x8FD8;&#x9700;&#x8981;&#x8F93;&#x51FA;&#x8F6C;&#x6362;&#x540E;&#x7684; ES5 &#x4EE3;&#x7801;&#x5BF9;&#x5E94;&#x7684; Source Map&#xFF0C;&#x4EE5;&#x65B9;&#x4FBF;&#x8C03;&#x8BD5;&#x6E90;&#x7801;&#x3002;
&#x4E3A;&#x4E86;&#x628A; Source Map &#x4E5F;&#x4E00;&#x8D77;&#x968F;&#x7740; ES5 &#x4EE3;&#x7801;&#x8FD4;&#x56DE;&#x7ED9; Webpack&#xFF0C;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x5199;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source</span>) </span>{
  <span class="hljs-comment">// &#x901A;&#x8FC7; this.callback &#x544A;&#x8BC9; Webpack &#x8FD4;&#x56DE;&#x7684;&#x7ED3;&#x679C;</span>
  <span class="hljs-keyword">this</span>.callback(<span class="hljs-literal">null</span>, source, sourceMaps);
  <span class="hljs-comment">// &#x5F53;&#x4F60;&#x4F7F;&#x7528; this.callback &#x8FD4;&#x56DE;&#x5185;&#x5BB9;&#x65F6;&#xFF0C;&#x8BE5; Loader &#x5FC5;&#x987B;&#x8FD4;&#x56DE; undefined&#xFF0C;</span>
  <span class="hljs-comment">// &#x4EE5;&#x8BA9; Webpack &#x77E5;&#x9053;&#x8BE5; Loader &#x8FD4;&#x56DE;&#x7684;&#x7ED3;&#x679C;&#x5728; this.callback &#x4E2D;&#xFF0C;&#x800C;&#x4E0D;&#x662F; return &#x4E2D; </span>
  <span class="hljs-keyword">return</span>;
};
</code></pre>
<p>&#x5176;&#x4E2D;&#x7684; <code>this.callback</code> &#x662F; Webpack &#x7ED9; Loader &#x6CE8;&#x5165;&#x7684; API&#xFF0C;&#x4EE5;&#x65B9;&#x4FBF; Loader &#x548C; Webpack &#x4E4B;&#x95F4;&#x901A;&#x4FE1;&#x3002;
<code>this.callback</code> &#x7684;&#x8BE6;&#x7EC6;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">this</span>.callback(
    <span class="hljs-comment">// &#x5F53;&#x65E0;&#x6CD5;&#x8F6C;&#x6362;&#x539F;&#x5185;&#x5BB9;&#x65F6;&#xFF0C;&#x7ED9; Webpack &#x8FD4;&#x56DE;&#x4E00;&#x4E2A; Error</span>
    err: <span class="hljs-built_in">Error</span> | <span class="hljs-literal">null</span>,
    <span class="hljs-comment">// &#x539F;&#x5185;&#x5BB9;&#x8F6C;&#x6362;&#x540E;&#x7684;&#x5185;&#x5BB9;</span>
    content: string | Buffer,
    <span class="hljs-comment">// &#x7528;&#x4E8E;&#x628A;&#x8F6C;&#x6362;&#x540E;&#x7684;&#x5185;&#x5BB9;&#x5F97;&#x51FA;&#x539F;&#x5185;&#x5BB9;&#x7684; Source Map&#xFF0C;&#x65B9;&#x4FBF;&#x8C03;&#x8BD5;</span>
    sourceMap?: SourceMap,
    <span class="hljs-comment">// &#x5982;&#x679C;&#x672C;&#x6B21;&#x8F6C;&#x6362;&#x4E3A;&#x539F;&#x5185;&#x5BB9;&#x751F;&#x6210;&#x4E86; AST &#x8BED;&#x6CD5;&#x6811;&#xFF0C;&#x53EF;&#x4EE5;&#x628A;&#x8FD9;&#x4E2A; AST &#x8FD4;&#x56DE;&#xFF0C;</span>
    <span class="hljs-comment">// &#x4EE5;&#x65B9;&#x4FBF;&#x4E4B;&#x540E;&#x9700;&#x8981; AST &#x7684; Loader &#x590D;&#x7528;&#x8BE5; AST&#xFF0C;&#x4EE5;&#x907F;&#x514D;&#x91CD;&#x590D;&#x751F;&#x6210; AST&#xFF0C;&#x63D0;&#x5347;&#x6027;&#x80FD;</span>
    abstractSyntaxTree?: AST
);
</code></pre>
<blockquote>
<p>Source Map &#x7684;&#x751F;&#x6210;&#x5F88;&#x8017;&#x65F6;&#xFF0C;&#x901A;&#x5E38;&#x5728;&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x4E0B;&#x624D;&#x4F1A;&#x751F;&#x6210; Source Map&#xFF0C;&#x5176;&#x5B83;&#x73AF;&#x5883;&#x4E0B;&#x4E0D;&#x7528;&#x751F;&#x6210;&#xFF0C;&#x4EE5;&#x52A0;&#x901F;&#x6784;&#x5EFA;&#x3002;
&#x4E3A;&#x6B64; Webpack &#x4E3A; Loader &#x63D0;&#x4F9B;&#x4E86; <code>this.sourceMap</code> API &#x53BB;&#x544A;&#x8BC9; Loader &#x5F53;&#x524D;&#x6784;&#x5EFA;&#x73AF;&#x5883;&#x4E0B;&#x7528;&#x6237;&#x662F;&#x5426;&#x9700;&#x8981; Source Map&#x3002;
&#x5982;&#x679C;&#x4F60;&#x7F16;&#x5199;&#x7684; Loader &#x4F1A;&#x751F;&#x6210; Source Map&#xFF0C;&#x8BF7;&#x8003;&#x8651;&#x5230;&#x8FD9;&#x70B9;&#x3002;</p>
</blockquote>
<h3 id="&#x540C;&#x6B65;&#x4E0E;&#x5F02;&#x6B65;">&#x540C;&#x6B65;&#x4E0E;&#x5F02;&#x6B65;</h3>
<p>Loader &#x6709;&#x540C;&#x6B65;&#x548C;&#x5F02;&#x6B65;&#x4E4B;&#x5206;&#xFF0C;&#x4E0A;&#x9762;&#x4ECB;&#x7ECD;&#x7684; Loader &#x90FD;&#x662F;&#x540C;&#x6B65;&#x7684; Loader&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x7684;&#x8F6C;&#x6362;&#x6D41;&#x7A0B;&#x90FD;&#x662F;&#x540C;&#x6B65;&#x7684;&#xFF0C;&#x8F6C;&#x6362;&#x5B8C;&#x6210;&#x540E;&#x518D;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x3002;
&#x4F46;&#x5728;&#x6709;&#x4E9B;&#x573A;&#x666F;&#x4E0B;&#x8F6C;&#x6362;&#x7684;&#x6B65;&#x9AA4;&#x53EA;&#x80FD;&#x662F;&#x5F02;&#x6B65;&#x5B8C;&#x6210;&#x7684;&#xFF0C;&#x4F8B;&#x5982;&#x4F60;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x624D;&#x80FD;&#x5F97;&#x51FA;&#x7ED3;&#x679C;&#xFF0C;&#x5982;&#x679C;&#x91C7;&#x7528;&#x540C;&#x6B65;&#x7684;&#x65B9;&#x5F0F;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x5C31;&#x4F1A;&#x963B;&#x585E;&#x6574;&#x4E2A;&#x6784;&#x5EFA;&#xFF0C;&#x5BFC;&#x81F4;&#x6784;&#x5EFA;&#x975E;&#x5E38;&#x7F13;&#x6162;&#x3002;</p>
<p>&#x5728;&#x8F6C;&#x6362;&#x6B65;&#x9AA4;&#x662F;&#x5F02;&#x6B65;&#x65F6;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source</span>) </span>{
    <span class="hljs-comment">// &#x544A;&#x8BC9; Webpack &#x672C;&#x6B21;&#x8F6C;&#x6362;&#x662F;&#x5F02;&#x6B65;&#x7684;&#xFF0C;Loader &#x4F1A;&#x5728; callback &#x4E2D;&#x56DE;&#x8C03;&#x7ED3;&#x679C;</span>
    <span class="hljs-keyword">var</span> callback = <span class="hljs-keyword">this</span>.async();
    someAsyncOperation(source, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, result, sourceMaps, ast</span>) </span>{
        <span class="hljs-comment">// &#x901A;&#x8FC7; callback &#x8FD4;&#x56DE;&#x5F02;&#x6B65;&#x6267;&#x884C;&#x540E;&#x7684;&#x7ED3;&#x679C;</span>
        callback(err, result, sourceMaps, ast);
    });
};
</code></pre>
<h3 id="&#x5904;&#x7406;&#x4E8C;&#x8FDB;&#x5236;&#x6570;&#x636E;">&#x5904;&#x7406;&#x4E8C;&#x8FDB;&#x5236;&#x6570;&#x636E;</h3>
<p>&#x5728;&#x9ED8;&#x8BA4;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;Webpack &#x4F20;&#x7ED9; Loader &#x7684;&#x539F;&#x5185;&#x5BB9;&#x90FD;&#x662F; UTF-8 &#x683C;&#x5F0F;&#x7F16;&#x7801;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x3002;
&#x4F46;&#x6709;&#x4E9B;&#x573A;&#x666F;&#x4E0B; Loader &#x4E0D;&#x662F;&#x5904;&#x7406;&#x6587;&#x672C;&#x6587;&#x4EF6;&#xFF0C;&#x800C;&#x662F;&#x5904;&#x7406;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;&#xFF0C;&#x4F8B;&#x5982; file-loader&#xFF0C;&#x5C31;&#x9700;&#x8981; Webpack &#x7ED9; Loader &#x4F20;&#x5165;&#x4E8C;&#x8FDB;&#x5236;&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;&#x3002;
&#x4E3A;&#x6B64;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x8FD9;&#x6837;&#x7F16;&#x5199; Loader&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source</span>) </span>{
    <span class="hljs-comment">// &#x5728; exports.raw === true &#x65F6;&#xFF0C;Webpack &#x4F20;&#x7ED9; Loader &#x7684; source &#x662F; Buffer &#x7C7B;&#x578B;&#x7684;</span>
    source <span class="hljs-keyword">instanceof</span> Buffer === <span class="hljs-literal">true</span>;
    <span class="hljs-comment">// Loader &#x8FD4;&#x56DE;&#x7684;&#x7C7B;&#x578B;&#x4E5F;&#x53EF;&#x4EE5;&#x662F; Buffer &#x7C7B;&#x578B;&#x7684;</span>
    <span class="hljs-comment">// &#x5728; exports.raw !== true &#x65F6;&#xFF0C;Loader &#x4E5F;&#x53EF;&#x4EE5;&#x8FD4;&#x56DE; Buffer &#x7C7B;&#x578B;&#x7684;&#x7ED3;&#x679C;</span>
    <span class="hljs-keyword">return</span> source;
};
<span class="hljs-comment">// &#x901A;&#x8FC7; exports.raw &#x5C5E;&#x6027;&#x544A;&#x8BC9; Webpack &#x8BE5; Loader &#x662F;&#x5426;&#x9700;&#x8981;&#x4E8C;&#x8FDB;&#x5236;&#x6570;&#x636E; </span>
<span class="hljs-built_in">module</span>.exports.raw = <span class="hljs-literal">true</span>;
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x4E2D;&#x6700;&#x5173;&#x952E;&#x7684;&#x4EE3;&#x7801;&#x662F;&#x6700;&#x540E;&#x4E00;&#x884C; <code>module.exports.raw = true;</code>&#xFF0C;&#x6CA1;&#x6709;&#x8BE5;&#x884C; Loader &#x53EA;&#x80FD;&#x62FF;&#x5230;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<h3 id="&#x7F13;&#x5B58;&#x52A0;&#x901F;">&#x7F13;&#x5B58;&#x52A0;&#x901F;</h3>
<p>&#x5728;&#x6709;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6709;&#x4E9B;&#x8F6C;&#x6362;&#x64CD;&#x4F5C;&#x9700;&#x8981;&#x5927;&#x91CF;&#x8BA1;&#x7B97;&#x975E;&#x5E38;&#x8017;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x6BCF;&#x6B21;&#x6784;&#x5EFA;&#x90FD;&#x91CD;&#x65B0;&#x6267;&#x884C;&#x91CD;&#x590D;&#x7684;&#x8F6C;&#x6362;&#x64CD;&#x4F5C;&#xFF0C;&#x6784;&#x5EFA;&#x5C06;&#x4F1A;&#x53D8;&#x5F97;&#x975E;&#x5E38;&#x7F13;&#x6162;&#x3002;
&#x4E3A;&#x6B64;&#xFF0C;Webpack &#x4F1A;&#x9ED8;&#x8BA4;&#x7F13;&#x5B58;&#x6240;&#x6709; Loader &#x7684;&#x5904;&#x7406;&#x7ED3;&#x679C;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x5728;&#x9700;&#x8981;&#x88AB;&#x5904;&#x7406;&#x7684;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x5176;&#x4F9D;&#x8D56;&#x7684;&#x6587;&#x4EF6;&#x6CA1;&#x6709;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#xFF0C;
&#x662F;&#x4E0D;&#x4F1A;&#x91CD;&#x65B0;&#x8C03;&#x7528;&#x5BF9;&#x5E94;&#x7684; Loader &#x53BB;&#x6267;&#x884C;&#x8F6C;&#x6362;&#x64CD;&#x4F5C;&#x7684;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4F60;&#x60F3;&#x8BA9; Webpack &#x4E0D;&#x7F13;&#x5B58;&#x8BE5; Loader &#x7684;&#x5904;&#x7406;&#x7ED3;&#x679C;&#xFF0C;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">source</span>) </span>{
  <span class="hljs-comment">// &#x5173;&#x95ED;&#x8BE5; Loader &#x7684;&#x7F13;&#x5B58;&#x529F;&#x80FD;</span>
  <span class="hljs-keyword">this</span>.cacheable(<span class="hljs-literal">false</span>);
  <span class="hljs-keyword">return</span> source;
};
</code></pre>
<h2 id="&#x5176;&#x5B83;-loader-api">&#x5176;&#x5B83; Loader API</h2>
<p>&#x9664;&#x4E86;&#x4EE5;&#x4E0A;&#x63D0;&#x5230;&#x7684;&#x5728; Loader &#x4E2D;&#x80FD;&#x8C03;&#x7528;&#x7684; Webpack API &#x5916;&#xFF0C;&#x8FD8;&#x5B58;&#x5728;&#x4EE5;&#x4E0B;&#x5E38;&#x7528; API&#xFF1A;</p>
<ul>
<li><p><code>this.context</code>&#xFF1A;&#x5F53;&#x524D;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x7684;&#x6240;&#x5728;&#x76EE;&#x5F55;&#xFF0C;&#x5047;&#x5982;&#x5F53;&#x524D; Loader &#x5904;&#x7406;&#x7684;&#x6587;&#x4EF6;&#x662F; <code>/src/main.js</code>&#xFF0C;&#x5219; <code>this.context</code> &#x5C31;&#x7B49;&#x4E8E; <code>/src</code>&#x3002;</p>
</li>
<li><p><code>this.resource</code>&#xFF1A;&#x5F53;&#x524D;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x7684;&#x5B8C;&#x6574;&#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#xFF0C;&#x5305;&#x62EC; querystring&#xFF0C;&#x4F8B;&#x5982; <code>/src/main.js?name=1</code>&#x3002;</p>
</li>
<li><p><code>this.resourcePath</code>&#xFF1A;&#x5F53;&#x524D;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#xFF0C;&#x4F8B;&#x5982; <code>/src/main.js</code>&#x3002;</p>
</li>
<li><p><code>this.resourceQuery</code>&#xFF1A;&#x5F53;&#x524D;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x7684; querystring&#x3002;</p>
</li>
<li><p><code>this.target</code>&#xFF1A;&#x7B49;&#x4E8E; Webpack &#x914D;&#x7F6E;&#x4E2D;&#x7684; Target&#xFF0C;&#x8BE6;&#x60C5;&#x89C1; <a href="../2&#x914D;&#x7F6E;/2-7&#x5176;&#x5B83;&#x914D;&#x7F6E;&#x9879;.html#Target">2-7&#x5176;&#x5B83;&#x914D;&#x7F6E;&#x9879;-Target</a>&#x3002;</p>
</li>
<li><p><code>this.loadModule</code>&#xFF1A;&#x5F53; Loader &#x5728;&#x5904;&#x7406;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x4F9D;&#x8D56;&#x5176;&#x5B83;&#x6587;&#x4EF6;&#x7684;&#x5904;&#x7406;&#x7ED3;&#x679C;&#x624D;&#x80FD;&#x5F97;&#x51FA;&#x5F53;&#x524D;&#x6587;&#x4EF6;&#x7684;&#x7ED3;&#x679C;&#x65F6;&#xFF0C;
&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>this.loadModule(request: string, callback: function(err, source, sourceMap, module))</code> &#x53BB;&#x83B7;&#x5F97; <code>request</code> &#x5BF9;&#x5E94;&#x6587;&#x4EF6;&#x7684;&#x5904;&#x7406;&#x7ED3;&#x679C;&#x3002;</p>
</li>
<li><p><code>this.resolve</code>&#xFF1A;&#x50CF; <code>require</code> &#x8BED;&#x53E5;&#x4E00;&#x6837;&#x83B7;&#x5F97;&#x6307;&#x5B9A;&#x6587;&#x4EF6;&#x7684;&#x5B8C;&#x6574;&#x8DEF;&#x5F84;&#xFF0C;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x4E3A; <code>resolve(context: string, request: string, callback: function(err, result: string))</code>&#x3002;</p>
</li>
<li><p><code>this.addDependency</code>&#xFF1A;&#x7ED9;&#x5F53;&#x524D;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x6DFB;&#x52A0;&#x5176;&#x4F9D;&#x8D56;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x4EE5;&#x4FBF;&#x518D;&#x5176;&#x4F9D;&#x8D56;&#x7684;&#x6587;&#x4EF6;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#xFF0C;&#x4F1A;&#x91CD;&#x65B0;&#x8C03;&#x7528; Loader &#x5904;&#x7406;&#x8BE5;&#x6587;&#x4EF6;&#x3002;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x4E3A; <code>addDependency(file: string)</code>&#x3002;</p>
</li>
<li><p><code>this.addContextDependency</code>&#xFF1A;&#x548C; <code>addDependency</code> &#x7C7B;&#x4F3C;&#xFF0C;&#x4F46; <code>addContextDependency</code> &#x662F;&#x628A;&#x6574;&#x4E2A;&#x76EE;&#x5F55;&#x52A0;&#x5165;&#x5230;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x7684;&#x4F9D;&#x8D56;&#x4E2D;&#x3002;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x4E3A; <code>addContextDependency(directory: string)</code>&#x3002;</p>
</li>
<li><p><code>this.clearDependencies</code>&#xFF1A;&#x6E05;&#x9664;&#x5F53;&#x524D;&#x6B63;&#x5728;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x7684;&#x6240;&#x6709;&#x4F9D;&#x8D56;&#xFF0C;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x4E3A; <code>clearDependencies()</code>&#x3002;</p>
</li>
<li><p><code>this.emitFile</code>&#xFF1A;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x4E3A; <code>emitFile(name: string, content: Buffer|string, sourceMap: {...})</code>&#x3002;</p>
</li>
</ul>
<p>&#x5176;&#x5B83;&#x6CA1;&#x6709;&#x63D0;&#x5230;&#x7684; API &#x53EF;&#x4EE5;&#x53BB; <a href="https://webpack.js.org/api/loaders/" target="_blank">Webpack &#x5B98;&#x7F51;</a> &#x67E5;&#x770B;&#x3002; </p>
<h2 id="&#x52A0;&#x8F7D;&#x672C;&#x5730;-loader">&#x52A0;&#x8F7D;&#x672C;&#x5730; Loader</h2>
<p>&#x5728;&#x5F00;&#x53D1; Loader &#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x4E3A;&#x4E86;&#x6D4B;&#x8BD5;&#x7F16;&#x5199;&#x7684; Loader &#x662F;&#x5426;&#x80FD;&#x6B63;&#x5E38;&#x5DE5;&#x4F5C;&#xFF0C;&#x9700;&#x8981;&#x628A;&#x5B83;&#x914D;&#x7F6E;&#x5230; Webpack &#x4E2D;&#x540E;&#xFF0C;&#x624D;&#x53EF;&#x80FD;&#x4F1A;&#x8C03;&#x7528;&#x8BE5; Loader&#x3002;
&#x5728;&#x524D;&#x9762;&#x7684;&#x7AE0;&#x8282;&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;&#x7684; Loader &#x90FD;&#x662F;&#x901A;&#x8FC7; Npm &#x5B89;&#x88C5;&#x7684;&#xFF0C;&#x8981;&#x4F7F;&#x7528; Loader &#x65F6;&#x4F1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528; Loader &#x7684;&#x540D;&#x79F0;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-built_in">module</span>: {
    rules: [
      {
        test: <span class="hljs-regexp">/\.css$/</span>,
        use: [<span class="hljs-string">&apos;style-loader&apos;</span>],
      },
    ]
  },
};
</code></pre>
<p>&#x5982;&#x679C;&#x8FD8;&#x91C7;&#x53D6;&#x4EE5;&#x4E0A;&#x7684;&#x65B9;&#x6CD5;&#x53BB;&#x4F7F;&#x7528;&#x672C;&#x5730;&#x5F00;&#x53D1;&#x7684; Loader &#x5C06;&#x4F1A;&#x5F88;&#x9EBB;&#x70E6;&#xFF0C;&#x56E0;&#x4E3A;&#x4F60;&#x9700;&#x8981;&#x786E;&#x4FDD;&#x7F16;&#x5199;&#x7684; Loader &#x7684;&#x6E90;&#x7801;&#x662F;&#x5728; <code>node_modules</code> &#x76EE;&#x5F55;&#x4E0B;&#x3002;
&#x4E3A;&#x6B64;&#x4F60;&#x9700;&#x8981;&#x5148;&#x628A;&#x7F16;&#x5199;&#x7684; Loader &#x53D1;&#x5E03;&#x5230; Npm &#x4ED3;&#x5E93;&#x540E;&#x518D;&#x5B89;&#x88C5;&#x5230;&#x672C;&#x5730;&#x9879;&#x76EE;&#x4F7F;&#x7528;&#x3002;</p>
<p>&#x89E3;&#x51B3;&#x4EE5;&#x4E0A;&#x95EE;&#x9898;&#x7684;&#x4FBF;&#x6377;&#x65B9;&#x6CD5;&#x6709;&#x4E24;&#x79CD;&#xFF0C;&#x5206;&#x522B;&#x5982;&#x4E0B;&#xFF1A;</p>
<h4 id="npm-link">Npm link</h4>
<p>Npm link &#x4E13;&#x95E8;&#x7528;&#x4E8E;&#x5F00;&#x53D1;&#x548C;&#x8C03;&#x8BD5;&#x672C;&#x5730; Npm &#x6A21;&#x5757;&#xFF0C;&#x80FD;&#x505A;&#x5230;&#x5728;&#x4E0D;&#x53D1;&#x5E03;&#x6A21;&#x5757;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x628A;&#x672C;&#x5730;&#x7684;&#x4E00;&#x4E2A;&#x6B63;&#x5728;&#x5F00;&#x53D1;&#x7684;&#x6A21;&#x5757;&#x7684;&#x6E90;&#x7801;&#x94FE;&#x63A5;&#x5230;&#x9879;&#x76EE;&#x7684; <code>node_modules</code> &#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x8BA9;&#x9879;&#x76EE;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x672C;&#x5730;&#x7684; Npm &#x6A21;&#x5757;&#x3002;
&#x7531;&#x4E8E;&#x662F;&#x901A;&#x8FC7;&#x8F6F;&#x94FE;&#x63A5;&#x7684;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x7F16;&#x8F91;&#x4E86;&#x672C;&#x5730;&#x7684; Npm &#x6A21;&#x5757;&#x4EE3;&#x7801;&#xFF0C;&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x4E5F;&#x80FD;&#x4F7F;&#x7528;&#x5230;&#x7F16;&#x8F91;&#x540E;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<p>&#x5B8C;&#x6210; Npm link &#x7684;&#x6B65;&#x9AA4;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>&#x786E;&#x4FDD;&#x6B63;&#x5728;&#x5F00;&#x53D1;&#x7684;&#x672C;&#x5730; Npm &#x6A21;&#x5757;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x6B63;&#x5728;&#x5F00;&#x53D1;&#x7684; Loader&#xFF09;&#x7684; <code>package.json</code> &#x5DF2;&#x7ECF;&#x6B63;&#x786E;&#x914D;&#x7F6E;&#x597D;&#xFF1B;</li>
<li>&#x5728;&#x672C;&#x5730; Npm &#x6A21;&#x5757;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x6267;&#x884C; <code>npm link</code>&#xFF0C;&#x628A;&#x672C;&#x5730;&#x6A21;&#x5757;&#x6CE8;&#x518C;&#x5230;&#x5168;&#x5C40;&#xFF1B;</li>
<li>&#x5728;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E0B;&#x6267;&#x884C; <code>npm link loader-name</code>&#xFF0C;&#x628A;&#x7B2C;2&#x6B65;&#x6CE8;&#x518C;&#x5230;&#x5168;&#x5C40;&#x7684;&#x672C;&#x5730; Npm &#x6A21;&#x5757;&#x94FE;&#x63A5;&#x5230;&#x9879;&#x76EE;&#x7684; <code>node_moduels</code> &#x4E0B;&#xFF0C;&#x5176;&#x4E2D;&#x7684; <code>loader-name</code> &#x662F;&#x6307;&#x5728;&#x7B2C;1&#x6B65;&#x4E2D;&#x7684; <code>package.json</code> &#x6587;&#x4EF6;&#x4E2D;&#x914D;&#x7F6E;&#x7684;&#x6A21;&#x5757;&#x540D;&#x79F0;&#x3002;</li>
</ol>
<p>&#x94FE;&#x63A5;&#x597D; Loader &#x5230;&#x9879;&#x76EE;&#x540E;&#x4F60;&#x5C31;&#x53EF;&#x4EE5;&#x50CF;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x771F;&#x6B63;&#x7684; Npm &#x6A21;&#x5757;&#x4E00;&#x6837;&#x4F7F;&#x7528;&#x672C;&#x5730;&#x7684; Loader &#x4E86;&#x3002;</p>
<h4 id="resolveloader">ResolveLoader</h4>
<p>&#x5728; <a href="../2&#x914D;&#x7F6E;/2-7&#x5176;&#x5B83;&#x914D;&#x7F6E;&#x9879;.html#ResolveLoader">2-7&#x5176;&#x5B83;&#x914D;&#x7F6E;&#x9879;</a> &#x4E2D;&#x66FE;&#x4ECB;&#x7ECD;&#x8FC7; ResolveLoader &#x7528;&#x4E8E;&#x914D;&#x7F6E; Webpack &#x5982;&#x4F55;&#x5BFB;&#x627E; Loader&#x3002;
&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x53EA;&#x4F1A;&#x53BB; <code>node_modules</code> &#x76EE;&#x5F55;&#x4E0B;&#x5BFB;&#x627E;&#xFF0C;&#x4E3A;&#x4E86;&#x8BA9; Webpack &#x52A0;&#x8F7D;&#x653E;&#x5728;&#x672C;&#x5730;&#x9879;&#x76EE;&#x4E2D;&#x7684; Loader &#x9700;&#x8981;&#x4FEE;&#x6539; <code>resolveLoader.modules</code>&#x3002;</p>
<p>&#x5047;&#x5982;&#x672C;&#x5730;&#x7684; Loader &#x5728;&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x4E2D;&#x7684; <code>./loaders/loader-name</code> &#x4E2D;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x5982;&#x4E0B;&#x914D;&#x7F6E;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  resolveLoader:{
    <span class="hljs-comment">// &#x53BB;&#x54EA;&#x4E9B;&#x76EE;&#x5F55;&#x4E0B;&#x5BFB;&#x627E; Loader&#xFF0C;&#x6709;&#x5148;&#x540E;&#x987A;&#x5E8F;&#x4E4B;&#x5206;</span>
    modules: [<span class="hljs-string">&apos;node_modules&apos;</span>,<span class="hljs-string">&apos;./loaders/&apos;</span>],
  }
}
</code></pre>
<p>&#x52A0;&#x4E0A;&#x4EE5;&#x4E0A;&#x914D;&#x7F6E;&#x540E;&#xFF0C; Webpack &#x4F1A;&#x5148;&#x53BB; <code>node_modules</code> &#x9879;&#x76EE;&#x4E0B;&#x5BFB;&#x627E; Loader&#xFF0C;&#x5982;&#x679C;&#x627E;&#x4E0D;&#x5230;&#xFF0C;&#x4F1A;&#x518D;&#x53BB; <code>./loaders/</code> &#x76EE;&#x5F55;&#x4E0B;&#x5BFB;&#x627E;&#x3002;</p>
<h2 id="&#x5B9E;&#x6218;">&#x5B9E;&#x6218;</h2>
<p>&#x4E0A;&#x9762;&#x8BB2;&#x4E86;&#x8BB8;&#x591A;&#x7406;&#x8BBA;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x4ECE;&#x5B9E;&#x9645;&#x51FA;&#x53D1;&#xFF0C;&#x6765;&#x7F16;&#x5199;&#x4E00;&#x4E2A;&#x89E3;&#x51B3;&#x5B9E;&#x9645;&#x95EE;&#x9898;&#x7684; Loader&#x3002;</p>
<p>&#x8BE5; Loader &#x540D;&#x53EB; comment-require-loader&#xFF0C;&#x4F5C;&#x7528;&#x662F;&#x628A; JavaScript &#x4EE3;&#x7801;&#x4E2D;&#x7684;&#x6CE8;&#x91CA;&#x8BED;&#x6CD5;</p>
<pre><code class="lang-js"><span class="hljs-comment">// @require &apos;../style/index.css&apos;</span>
</code></pre>
<p>&#x8F6C;&#x6362;&#x6210;</p>
<pre><code class="lang-js"><span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../style/index.css&apos;</span>);
</code></pre>
<p>&#x8BE5; Loader &#x7684;&#x4F7F;&#x7528;&#x573A;&#x666F;&#x662F;&#x53BB;&#x6B63;&#x786E;&#x52A0;&#x8F7D;&#x9488;&#x5BF9; <a href="http://fis.baidu.com/fis3/docs/user-dev/require.html" target="_blank">Fis3</a> &#x7F16;&#x5199;&#x7684; JavaScript&#xFF0C;&#x8FD9;&#x4E9B; JavaScript &#x4E2D;&#x5B58;&#x5728;&#x901A;&#x8FC7;&#x6CE8;&#x91CA;&#x7684;&#x65B9;&#x5F0F;&#x52A0;&#x8F7D;&#x4F9D;&#x8D56;&#x7684; CSS &#x6587;&#x4EF6;&#x3002;</p>
<p>&#x8BE5; Loader &#x7684;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-built_in">module</span>: {
    rules: [
      {
        test: <span class="hljs-regexp">/\.js$/</span>,
        use: [<span class="hljs-string">&apos;comment-require-loader&apos;</span>],
        <span class="hljs-comment">// &#x9488;&#x5BF9;&#x91C7;&#x7528;&#x4E86; fis3 CSS &#x5BFC;&#x5165;&#x8BED;&#x6CD5;&#x7684; JavaScript &#x6587;&#x4EF6;&#x901A;&#x8FC7; comment-require-loader &#x53BB;&#x8F6C;&#x6362; </span>
        include: [path.resolve(__dirname, <span class="hljs-string">&apos;node_modules/imui&apos;</span>)]
      }
    ]
  }
};
</code></pre>
<p>&#x8BE5; Loader &#x7684;&#x5B9E;&#x73B0;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x5B8C;&#x6574;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">replace</span>(<span class="hljs-params">source</span>) </span>{
    <span class="hljs-comment">// &#x4F7F;&#x7528;&#x6B63;&#x5219;&#x628A; // @require &apos;../style/index.css&apos; &#x8F6C;&#x6362;&#x6210; require(&apos;../style/index.css&apos;);  </span>
    <span class="hljs-keyword">return</span> source.replace(<span class="hljs-regexp">/(\/\/ *@require) +((&apos;|&quot;).+(&apos;|&quot;)).*/</span>, <span class="hljs-string">&apos;require($2);&apos;</span>);
}

<span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">content</span>) </span>{
    <span class="hljs-keyword">return</span> replace(content);
};
</code></pre>
<blockquote>
<p>&#x672C;&#x5B9E;&#x4F8B;<a href="https://github.com/gwuhaolin/comment-require-loader" target="_blank">&#x63D0;&#x4F9B;&#x9879;&#x76EE;&#x5B8C;&#x6574;&#x4EE3;&#x7801;</a></p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="5-2输出文件分析.html" class="navigation navigation-prev " aria-label="Previous page: 5-2 输出文件分析">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="5-4编写Plugin.html" class="navigation navigation-next " aria-label="Next page: 5-4 编写 Plugin">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"5-3 编写 Loader","level":"1.7.3","depth":2,"next":{"title":"5-4 编写 Plugin","level":"1.7.4","depth":2,"path":"5原理/5-4编写Plugin.md","ref":"5原理/5-4编写Plugin.md","articles":[]},"previous":{"title":"5-2 输出文件分析","level":"1.7.2","depth":2,"path":"5原理/5-2输出文件分析.md","ref":"5原理/5-2输出文件分析.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github-buttons","ga","modal","adsense"],"root":"./docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search":{},"adsense":{"client":"ca-pub-9697944574373240","slot":"9319793387","format":"auto","element":".page-inner section","position":"top"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"modal":{"closable":true,"excludeUrls":["\\?q=.+$","index.html","前言.html","\\/$","1-.+","2-2Output","3-1使用ES6语言","3-2使用TypeScript语言","3-4使用SCSS语言.html","3-5使用PostCSS.html","3-6使用React框架","3-7使用Vue框架","3-8使用Angular2框架","3-9为单页应用生成HTML","3-10管理多个单页应用","3-17通过Node.jsAPI启动Webpack","3-20加载SVG"],"html":"<div style='text-align: center'><a href='http://union-click.jd.com/jdc?d=1AMcaz'><img src='http://p0.meituan.net/scarlett/df16c51ffb95186df6f75d8c0e22b965842464.png' width='306px' height='411px'><a/> <h2><a target='_blank' href='http://union-click.jd.com/jdc?d=1AMcaz'>购买本书纸质版</a></h2></div>"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]},"ga":{"configuration":"auto","token":"UA-54964850-3"},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"吴浩麟","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"9787121331725","variables":{},"title":"深入浅出 Webpack","language":"zh-hans","gitbook":"*","description":"本书按照入门、配置、实战、优化、原理的路线层层深入，涵盖了 Webpack 的方方面面。对于小白，本书可以作为 Webpack 入门教程，对于老手，本书可以进一步加深你对 Webpack 的理解。"},"file":{"path":"5原理/5-3编写Loader.md","mtime":"2019-02-28T08:16:23.303Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-12-22T08:51:47.376Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-ga/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-modal/index.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-adsense/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

